package com.xrtn.controller;

import com.xrtn.bean.SysRoleInfo;
import com.xrtn.service.IRoleService;
import com.xrtn.utils.CodeEnum;
import com.xrtn.utils.ResponseData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.WebParam;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by tu_pei on 2018/3/21.
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    /**
     * 进入病历管理页面
     * @return
     */
    @RequestMapping(value = "/gotoRole",method = RequestMethod.GET)
    @ResponseBody
    public ModelAndView gotoRole(ModelAndView modelAndView){
        modelAndView.setViewName("basicSettingPos");
        return modelAndView;
    }
    /**
     * 进入病历管理页面
     * @return
     */
    @RequestMapping(value = "/gotoAddRole",method = RequestMethod.GET)
    @ResponseBody
    public ModelAndView gotoAddRole(ModelAndView modelAndView){
        modelAndView.setViewName("basicSettingPosAdd");
        return modelAndView;
    }

    /**
     * @Title: selectSysRoleList
     * @Description: 查询所有职位列表
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "查询所有职位列表",notes="查询所有职位列表")
    @RequestMapping(value = "/selectSysRoleList", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData selectSysRoleList(){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(roleService.selectSysRoleList());
        // 返回数据
        return data;
    }

    /**
     * @Title: selectRoleList
     * @Description: 查询职位权限列表
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "查询职位权限列表",notes="查询职位权限列表")
    @RequestMapping(value = "/selectRoleList", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="roleId",dataType="int",required=true,value="角色id",defaultValue = "1"),
    })
    @ResponseBody
    public ResponseData selectRoleList(Integer roleId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(roleService.selectRoleList(roleId));
        // 返回数据
        return data;
    }

    /**
     * @Title: saveRole
     * @Description: 保存职位权限
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "保存职位权限",notes="保存职位权限")
    @RequestMapping(value = "/saveRole", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="roleId",dataType="int",required=false,value="角色id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="roleName",dataType="string",required=false,value="角色名称",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="subclinicIds",dataType="int",required=false,value="权限范围",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="roleDesc",dataType="string",required=false,value="职位描述",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="roleList",dataType="string",required=false,value="权限数组",defaultValue = "[{\n" + "\"menuId\": 1,\n" + "\"menuName\": \"工作台\",\n" + "\"functionId\": 1,\n" + "\"functionName\": \"快捷菜单\",\n" + "\"roleId\": 1\n" + "}]")
    })
    @ResponseBody
    public ResponseData saveRole(SysRoleInfo roleInfo,String roleList){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        Integer count = roleService.saveRole(roleInfo,roleList);
        if( count <= 0 ){
              data.setCodeEnum(CodeEnum.CODE_6);
              return data;
        }
        // 返回数据
        return data;
    }

    /**
     * @Title: deleteRole
     * @Description: 删除职位
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "删除职位",notes="删除职位")
    @RequestMapping(value = "/deleteRole", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="roleId",dataType="int",required=true,value="角色id",defaultValue = "1"),
    })
    @ResponseBody
    public ResponseData deleteRole(Integer roleId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        Integer count = roleService.deleteRole(roleId);
        if( count <= 0 ){
            data.setCodeEnum(CodeEnum.CODE_10012);
            return data;
        }
        // 返回数据
        return data;
    }


}
